import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:h_flutter_119/res/colors.dart';
import 'package:h_flutter_119/res/style.dart';
import 'package:h_flutter_119/route/route_utils.dart';

import '../../find/model/Focus_Item_Entity.dart';

class RankItemWidget extends StatelessWidget {
  FocusItemEntity entity;

  RankItemWidget(this.entity, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Map<String, dynamic> map = {};
        map["playUrl"] = entity.data?.playUrl ?? "";
        map["coverUrl"] = entity.data?.cover?.feed ?? "";
        map["videoId"] = entity.data?.id.toString() ?? "";
        goVideoDetail(context, map);
      },
      child: _createContent(context),
    );
  }

  Widget _createContent(BuildContext context) => Card(
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(20.w))),
        child: Column(
          children: [
            Stack(
              children: [
                Container(
                  width: double.infinity,
                  height: 400.w,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(20.w))),
                  child: Hero(
                      tag: entity.data?.id ?? "",
                      child: CachedNetworkImage(
                          imageUrl: entity.data?.cover?.feed ?? "",
                          height: 400.w,
                          fit: BoxFit.cover)
                  ),
                ),
                Positioned(
                    top: 0,
                    left: 0,
                    child: Container(
                      padding: EdgeInsets.only(left: 25.w, right: 33.w),
                      height: 42.w,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.only(
                              topLeft: Radius.circular(20.w),
                              bottomRight: Radius.circular(42.w)),
                          color: ColorStyle.color_EA4C43),
                      child: Text(entity.data?.category ?? "",
                          style:
                              TextStyle(fontSize: 24.sp, color: Colors.white)),
                    ))
              ],
            ),
            SizedBox(
              height: 150.w,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  SizedBox(
                    width: 10.w,
                  ),
                  GestureDetector(
                    onTap: () {
                      goPhotoPreview(context, entity.data?.cover?.feed??"");
                    },
                    child: ClipOval(
                      child: CachedNetworkImage(
                          imageUrl: entity.data?.author?.icon ?? "",
                          height: 80.w,
                          width: 80.w,
                          fit: BoxFit.cover),
                    ),
                  ),
                  Box.wBox10,
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      SizedBox(width: 500.w,child: Text(
                        entity.data?.author?.name ?? "",
                        style: TextStyle(
                            fontSize: 30.sp,
                            fontWeight: FontWeight.bold,
                            color: ColorStyle.color_333333),
                        overflow: TextOverflow.ellipsis,
                        maxLines: 1,
                      ),),
                      Box.hBox15,
                      SizedBox(
                        width: 500.w,
                        child: Text(
                          entity.data?.author?.description??"",
                          style: TextStyle(
                              color: ColorStyle.color_999999,
                              fontSize: 27.sp,
                              fontWeight: FontWeight.normal,
                              overflow: TextOverflow.ellipsis
                          ),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      )
                    ],
                  )
                ],
              ),
            )
          ],
        ),
      );
}
